home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / +system+ / tools / gui / bgui.lha / bgui / Examples / Source / MultiFont.c < prev    next >
C/C++ Source or Header  |  2000-02-27  |  5KB  |  188 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/MultiFont.c,v 1.1.2.1 1998/02/28 17:45:34 mlemos Exp $
  3.  *
  4.  * MultiFont.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * $Log: MultiFont.c,v $
  12.  * Revision 1.1.2.1  1998/02/28 17:45:34  mlemos
  13.  * Ian sources
  14.  *
  15.  *
  16.  */
  17.  
  18. /*
  19. dcc MultiFont.c -mi -ms -mRR -proto -lbgui
  20. quit
  21. */
  22.  
  23. #include "DemoCode.h"
  24.  
  25. /*
  26.  *    Fonts used in the code.
  27.  */
  28. struct TextAttr ButtonFont    = { "diamond.font", 12, FS_NORMAL, FPF_DISKFONT };
  29. struct TextAttr Info1Font    = { "emerald.font", 17, FS_NORMAL, FPF_DISKFONT };
  30. struct TextAttr Info2Font    = { "opal.font",    9,  FS_NORMAL, FPF_DISKFONT };
  31.  
  32. struct TextFont *Button, *Info1, *Info2;
  33. struct Library    *DiskfontBase;
  34.  
  35. /*
  36.  *    Object ID's
  37.  */
  38. #define ID_QUIT                 1
  39.  
  40. /*
  41.  *    Info texts.
  42.  */
  43. UBYTE  *IText1 = ISEQ_C ISEQ_HIGHLIGHT "MultiFont";
  44. UBYTE  *IText2 = ISEQ_C "This demo shows you how you\n"
  45.          "can use different fonts inside a\n"
  46.          "single window.";
  47.  
  48. VOID StartDemo( void )
  49. {
  50.     struct Window        *window;
  51.     Object            *WO_Window, *GO_Quit;
  52.     ULONG             signal, rc;
  53.     BOOL             running = TRUE;
  54.  
  55.     /*
  56.      *    We need this one to open the fonts.
  57.      */
  58.     if ( DiskfontBase = OpenLibrary( "diskfont.library", 36 )) {
  59.         /*
  60.          *    We open the fonts ourselves since BGUI
  61.          *    opens all fonts with OpenFont() which
  62.          *    means that they have to be resident
  63.          *    in memory.
  64.          */
  65.         if ( Button = OpenDiskFont( &ButtonFont )) {
  66.             if ( Info1 = OpenDiskFont( &Info1Font )) {
  67.                 if ( Info2 = OpenDiskFont( &Info2Font )) {
  68.                     /*
  69.                      *    Create the window object.
  70.                      */
  71.                     WO_Window = WindowObject,
  72.                         WINDOW_Title,        "Multi-Font Demo",
  73.                         WINDOW_AutoAspect,    TRUE,
  74.                         WINDOW_LockHeight,    TRUE,
  75.                         WINDOW_RMBTrap,         TRUE,
  76.                         WINDOW_MasterGroup,
  77.                             VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  78.                                 StartMember,
  79.                                     VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 2 ),
  80.                                         FRM_Type,        FRTYPE_BUTTON,
  81.                                         FRM_Recessed,        TRUE,
  82.                                         StartMember,
  83.                                             InfoObject,
  84.                                                 INFO_TextFormat,    IText1,
  85.                                                 INFO_HorizOffset,    0,
  86.                                                 INFO_VertOffset,    0,
  87.                                                 INFO_FixTextWidth,    TRUE,
  88.                                                 INFO_MinLines,        1,
  89.                                                 BT_TextAttr,        &Info1Font,
  90.                                             EndObject,
  91.                                         EndMember,
  92.                                         StartMember,
  93.                                             HorizSeparator,
  94.                                         EndMember,
  95.                                         StartMember,
  96.                                             InfoObject,
  97.                                                 INFO_TextFormat,    IText2,
  98.                                                 INFO_HorizOffset,    0,
  99.                                                 INFO_VertOffset,    0,
  100.                                                 INFO_FixTextWidth,    TRUE,
  101.                                                 INFO_MinLines,        3,
  102.                                                 BT_TextAttr,        &Info2Font,
  103.                                             EndObject,
  104.                                         EndMember,
  105.                                     EndObject,
  106.                                 EndMember,
  107.                                 StartMember,
  108.                                     HGroupObject,
  109.                                         VarSpace( 50 ),
  110.                                         StartMember,
  111.                                             GO_Quit = ButtonObject,
  112.                                                 LAB_Label,    "_Quit",
  113.                                                 LAB_Underscore, '_',
  114.                                                 ButtonFrame,
  115.                                                 GA_ID,        ID_QUIT,
  116.                                                 BT_TextAttr,    &ButtonFont,
  117.                                             EndObject,
  118.                                         EndMember,
  119.                                         VarSpace( 50 ),
  120.                                     EndObject, FixMinHeight,
  121.                                 EndMember,
  122.                             EndObject,
  123.                     EndObject;
  124.  
  125.                     /*
  126.                      *    Object created OK?
  127.                      */
  128.                     if ( WO_Window ) {
  129.                         /*
  130.                          *    Assign the key to the button.
  131.                          */
  132.                         if ( GadgetKey( WO_Window, GO_Quit,  "q" )) {
  133.                             /*
  134.                              *    try to open the window.
  135.                              */
  136.                             if ( window = WindowOpen( WO_Window )) {
  137.                                 /*
  138.                                  *    Obtain it's wait mask.
  139.                                  */
  140.                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  141.                                 /*
  142.                                  *    Event loop...
  143.                                  */
  144.                                 do {
  145.                                     Wait( signal );
  146.                                     /*
  147.                                      *    Handle events.
  148.                                      */
  149.                                     while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  150.                                         /*
  151.                                          *    Evaluate return code.
  152.                                          */
  153.                                         switch ( rc ) {
  154.  
  155.                                             case    WMHI_CLOSEWINDOW:
  156.                                             case    ID_QUIT:
  157.                                                 running = FALSE;
  158.                                                 break;
  159.                                         }
  160.                                     }
  161.                                 } while ( running );
  162.                             } else
  163.                                 Tell( "Could not open the window\n" );
  164.                         } else
  165.                             Tell( "Could not assign gadget keys\n" );
  166.                         /*
  167.                          *    Disposing of the window object will
  168.                          *    also close the window if it is
  169.                          *    already opened and it will dispose of
  170.                          *    all objects attached to it.
  171.                          */
  172.                         DisposeObject( WO_Window );
  173.                     } else
  174.                         Tell( "Could not create the window object\n" );
  175.                     CloseFont( Info2 );
  176.                 } else
  177.                     Tell( "Could not open opal.font\n" );
  178.                 CloseFont( Info1 );
  179.             } else
  180.                 Tell( "Could not open emerald.font\n" );
  181.             CloseFont( Button );
  182.         } else
  183.             Tell( "Could not open diamond.font\n" );
  184.         CloseLibrary( DiskfontBase );
  185.     } else
  186.         Tell( "Could not open diskfont.library\n" );
  187. }
  188.